<?php

/**
 * This is the model class for table "{{cameras}}".
 *
 * The followings are the available columns in table '{{cameras}}':
 * @property integer $id
 * @property string $mac_addr
 * @property string $cam_id
 * @property string $tel_num
 * @property integer $project_id
 * @property string $video_url
 * @property integer $is_3g
 * @property integer $is_valid
 *
 * The followings are the available model relations:
 * @property Projects $project
 */
class Camera extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Camera the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{cameras}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('mac_addr, cam_id, tel_num, project_id, video_url', 'required'),
			array('project_id, is_3g, is_valid', 'numerical', 'integerOnly'=>true),
			array('mac_addr, cam_id, tel_num', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, mac_addr, cam_id, tel_num, project_id, video_url, is_3g, is_valid', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'project' => array(self::BELONGS_TO, 'Projects', 'project_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'mac_addr' => 'Mac Addr',
			'cam_id' => 'Cam',
			'tel_num' => 'Tel Num',
			'project_id' => 'Project',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('mac_addr',$this->mac_addr,true);
		$criteria->compare('cam_id',$this->cam_id,true);
		$criteria->compare('tel_num',$this->tel_num,true);
		$criteria->compare('project_id',$this->project_id);
		$criteria->compare('video_url',$this->video_url);
		$criteria->compare('is_3g',$this->is_3g);
		$criteria->compare('is_valid',$this->is_valid);
		
		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}